<?php

preg_match('/some text/mJ', $subject);
preg_grep('#some text#Ji', $input, $flags);

$text = preg_match_all(
    '/(?<!\\\\)     # not preceded by a backslash
      <             # an open bracket
      >             # close bracket
    /iJx',
    '[$1]',
    $text
  );

preg_Split(
    [
        'be' => '/single-quoted/J',
        'ce' => '#hash-chars (common)#j',
        'de' => '!exclamations (why not?!eJs',
    ], $subject, 2
);

\preg_replace_callback_array(
    [
        '~[a]+~J' => function ($match) {
            echo strlen($match[0]), ' matches for "a" found', PHP_EOL;
        },
        '~[b]+~i' => function ($match) {
            echo strlen($match[0]), ' matches for "b" found', PHP_EOL;
        }
    ],
    $subject
);

// Verify support for heredocs and nowdocs.
$text = preg_match_all(
    <<<'EOD'
/(?<!\\\\)     # not preceded by a backslash
  <            # an open bracket
  >            # close bracket
/iJx
EOD
    ,
    '[$1]',
    $text
  );

// Safeguard support for PHP 8 named parameters.
preg_grep(array: $input, pattern: '#some text#i'); // OK.
PREG_grep(array: $input, pattern: '#some text#Ji', flags: $flags); // Error.

// Recognize use of the PHP 8.2 "n" modifier.
preg_match('/.(.)./n', 'abc', $m);
preg_match('`.(?P<test>.).`n', 'abc', $m);
\preg_match('{.(?P<test>.).}n', 'abc', $m);

// Recognize use of the PHP 8.4 "r" modifier.
preg_match('/.(.)./ri', 'abc', $m);
preg_match('`.(?P<test>.).`r', 'abc', $m);
preg_match('{A\x{17f}\x{212a}Z}xr', 'abc', $m);

// Issue #1764 - safeguard against false positives for text within brackets.
preg_match_all( $my->get_regex('#regexp#J'), $text, $matches );
preg_match_all( $regexes[ $type . '#regexp#n' ], $text, $matches );
\Preg_Match_ALL( namespace\get_regex('#regexp#r'), $text, $matches );
preg_match_all( \get_regex('#regexp#J'), $text, $matches );

// Safeguard against false positives on method calls and namespaced function calls.
ClassName::preg_match_all('/some text/J', $subject);
$obj->preg_match('/some text/n', $subject);
$obj?->preg_replace_callback_array('/some text/r', $subject);
namespace\preg_match_all('/some text/r', $subject);
\Fully\Qualified\preg_match('/some text/n', $subject);
Partially\Qualified\preg_split('/some text/J', $subject);
